<?php

namespace App\Services;
use App\Services\EasyWeChatServices;
use Illuminate\Support\Facades\Log;

class SendCouponServices
{
    public function send_coupon($coupon_stock_id,$openid,$number){
        //$EasyWeChatServices = app()->make('\App\Services\EasyWeChatServices');
        //$app = $EasyWeChatServices->pay_app();
        $app = EasyWeChatServices::pay_app();
        //$app = app('EasyWechatService')->pay_app();
        //dd($app);
        // 获取代金券实例
        $coupon = $app->coupon;
        //发送代金券的数据包，只要有这四个就行了
        $couponData = [
            'coupon_stock_id'=>$coupon_stock_id,//批次
            'openid_count'=>1,
            'partner_trade_no'=>$number,
            'openid'=>$openid
        ];

        // 发送代金券
        $result = $coupon->send($couponData);
        Log::info('發劵數據'.json_encode($result));
        //$result = $coupon->stock($couponData);
       // dd($result);
        return $result;
    }
}